﻿using Elasticsearch.Synchronize.Common.Enum;
using Elasticsearch.Synchronize.Domain.Events;
using Elasticsearch.Synchronize.Domain.Interface;

namespace Elasticsearch.Synchronize.DomainEventHandler.Handler
{
    public class RemoveRuleItemEventHandler : MediatR.NotificationHandler<RemoveRuleItemDomainEvent>
    {
        private readonly ISynchronizeItemRepository _repository;

        public RemoveRuleItemEventHandler(ISynchronizeItemRepository repository)
        {
            _repository = repository;
        }

        protected override void HandleCore(RemoveRuleItemDomainEvent notification)
        {
            var item = notification.SynchronizeItem;
            item.Enabled = false;
            item.State = SyncState.Stopped;
            _repository.Update(item.Identity, item);
        }
    }
}